|
|
|
|
|
|
|
RayDisk has more useful scanline clipping capabilities than the RayPlane class because it is much more tightly bounded. In most other respects, the two classes are similar. Figure 17.13 shows program VBRay displaying three spheres and a disk. |
|
|
|
|
|
|
|
|
Like disks, polygons lie in a plane. The RayPolygon class is very similar to the RayDisk class. The only difference between the two classes lies in the way they find their intersections with rays in the FindT function. |
|
|
|
|
|
|
|
|
Both classes begin by determining whether the ray intersects the plane containing the polygon. The RayDisk class then uses the distance from the disk's center to the point of intersection to determine whether the point lies within the disk. |
|
|
|
|
|
|
|
|
The RayPolygon class must determine whether the point of intersection lies within the polygon. At first, this task might seem difficult. Actually, it is fairly easy if you use a modified version of the PointInside function described in Chapter 15, Hidden Surface Removal. This function determines whether a point lies within a two-dimensional polygon. In the present case, however, the polygon is three-dimensionalit does not lie in the X-Y plane. |
|
|
|
|
|
|
|
|
Fortunately, a point lies within a polygon if the projection of the point lies within the projection of the polygon for any reasonable projection, as shown in Figure 17.14. This means you can project the polygon onto the X-Y plane before you test to see if a point lies inside it. Then you can use the PointInside function from Chapter 15. |
|
|
|
|
|
|
|
|
This test can fail if the plane containing the polygon is perpendicular to the X-Y plane. In that case, the projections of all the points in the polygon lie along a line, so you cannot tell if the point lies in the projected polygon. |
|
|
|
|
|
|
|
|
If the plane is perpendicular to the X-Y plane, it must not be perpendicular to the X-Z plane, the Y-Z plane, or both. In that case, you can project the polygon onto one of those other planes before testing to see if the point lies within the polygon. |
|
|
|
|
|
|
|
|
Figure 17.13
Program VBRay displaying three spheres and a disk. |
|
|
|
|
|